package com.jiazhong.basic.pack0524.onetomany.service.impl;

import com.jiazhong.basic.pack0524.onetomany.bean.Dept;
import com.jiazhong.basic.pack0524.onetomany.bean.Emp;
import com.jiazhong.basic.pack0524.onetomany.dao.DeptDAO;
import com.jiazhong.basic.pack0524.onetomany.dao.EmpDAO;
import com.jiazhong.basic.pack0524.onetomany.service.DeptService;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class DeptServiceImpl implements DeptService {

    private DeptDAO ddao = new DeptDAO();
    private EmpDAO edao = new EmpDAO();

    @Override
    public Dept findById1(int deptNo) {
        // 1. 获取到部门信息
        Dept dept = ddao.findById1(deptNo);
        if (dept == null) {
            return null;
        }
        // 2. 获取到员工信息
        List<Emp> list = edao.findByDeptNo(deptNo);
        // 将list--->set
        Set<Emp> set = new HashSet<>(list);
        // 3. 组装
        dept.setEmps(set);
        return dept;
    }

    @Override
    public Dept findById2(int deptNo) {
        return ddao.findById2(deptNo);
    }
}
